package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.UserShoppingCartService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@RequiredArgsConstructor
@Slf4j
public class UserShoppingCartController {

    private final UserShoppingCartService userShoppingCartService;

    @GetMapping("/list")
    public Result<?> list(){
        List<ShoppingCart> shoppingCarts = userShoppingCartService.list();
        return Result.success(shoppingCarts);
    }

    @PostMapping("/add")
    public Result<?> add(@RequestBody ShoppingCart shoppingCart){
        userShoppingCartService.insertShoppingCart(shoppingCart);
        return Result.success();
    }

    @PostMapping("/sub")
    public Result<?> sub(@RequestBody ShoppingCart shoppingCart){
        userShoppingCartService.deleteSole(shoppingCart);
        return Result.success();
    }

    @DeleteMapping("/clean")
    public Result<?> clean(){
        userShoppingCartService.cleanShoppingCart();
        return Result.success();
    }
}
